package com.wikidot.designpatterns.composite.alternative1;

public class Client {

	public static void main(String[] args) {
		Component a = new Composite("a");
		Component ab1 = new Composite("ab1");
		Component ab2 = new Composite("ab2");
		Component ab1c1 = new Leaf("ab1c1");
		Component ab1c2 = new Leaf("ab1c2");
		Component ab2c1 = new Leaf("ab2c1");

		/*
		 * Build structure - we must cast Component to Composite to be able to
		 * add descendants.
		 */
		((Composite) ab1).addComponent(ab1c1);
		((Composite) ab1).addComponent(ab1c2);
		((Composite) ab2).addComponent(ab2c1);
		((Composite) a).addComponent(ab1);
		((Composite) a).addComponent(ab2);

		// Call business operation
		a.businessOperation();

		/*
		 * The following failure call is recognized at compile-time. Leaf
		 * instances do not poses composite structure logic and therefore there
		 * cannot be added any descendants.
		 */
		// ab1c1.addComponent(new Leaf("ab1c1d1"));
	}
}
